package com.sinosoft.flow;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 流程服务
 *
 * @author tangyongbo
 */
@EnableCaching
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
@MapperScan("com.sinosoft.flow.dao")
public class BMPSFlowApplication
{

    private static final Logger log = LoggerFactory.getLogger(BMPSFlowApplication.class);

    private static final String SWAGGER_PAGE = "swagger-ui.html";

    private static final String SERVER_SSL_KEY_STORE = "server.ssl.key-store";

    public static void main(String[] args) throws UnknownHostException
    {
        SpringApplication app = new SpringApplication(BMPSFlowApplication.class);
        Environment env=app.run(args).getEnvironment();
        String serverPort = env.getProperty("server.port");
        String protocol = "http";
        if (env.getProperty(SERVER_SSL_KEY_STORE) != null) {
            protocol = "https";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' start up! URLs:\n\t" +
                        "SWAGGER API: \t{}://{}:{}/{}\n\t" +
                        "Profile: \t\t{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort,
                SWAGGER_PAGE,
                env.getActiveProfiles());
        System.out.println("(♥◠‿◠)ﾉﾞ  业务流程服务模块启动成功   ლ(´ڡ`ლ)ﾞ ");
    }
}
